package cn.wp.ewallet.common.web.controller;

import cn.wp.common.core.Wp;
import cn.wp.common.core.dto.WpResult;
import cn.wp.common.core.plugin.verification.VerificationCodeService;
import cn.wp.common.core.web.annotation.ClearInterceptor;
import cn.wp.common.core.web.interceptor.LoginInterceptor;
import cn.wp.ewallet.common.service.SmsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 短信控制层
 * create by ganjie
 */
@RestController
@Api(tags = "文档信息")
@RequestMapping(Wp.WebContext + "/ewallet/common/sms")
@Slf4j
public class SmsController {

    @Autowired
    private SmsService smsService;

    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     *
     * 发送短信验证码
     *
     * @return
     * @throws IOException
     */
    @RequestMapping("sendSmsCode")
    @ResponseBody
    @ClearInterceptor(LoginInterceptor.class)
    public WpResult sendEmailCode(String phone,String mobilePrefix) {
        //生成并保存验证码
        String smsCode = verificationCodeService.genCode(phone,6);
        log.info("send smsCode to phone:" + phone + ",smsSode = " + smsCode);
        //smsService.sendSmsCode(phone,mobilePrefix,smsCode);
        log.info("send smsCode to phone:" + phone + " success");
        return new WpResult().success(smsCode);
    }



}
